﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace WPFTestSolution.Pages.Controls.ItemsControls.MenuBases {
    
    /**
     * https://www.bilibili.com/video/BV1bV411A7Eq?p=59
     * 059-Menu菜单(: MenuBase : ItemsControl)
     * https://www.wpfsoft.com/2023/09/08/1916.html
     */
    public partial class _59_Menu_Page : Page {
        
        private class MenuModel {
            public string Name { get; set; }
            public List<MenuModel> Children { get; set; } = new List<MenuModel>();
            public string View { get; set; }
        }
        
        public _59_Menu_Page() {
            InitializeComponent();
            this.Title = "059-Menu菜单(: MenuBase : ItemsControl)";
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e) {
            if (sender is MenuItem item) {
                _TextBlock.Text = $"你单击了: {item.Header}";
            }
        }

        
        private List<MenuModel> Menus2 { get; set; } = new List<MenuModel>();

        private void Button_Inflate_OnClick(object sender, RoutedEventArgs e) {
            for (int i = 0; i < 5; i++) {
                MenuModel parent = new MenuModel {
                    Name = "一级菜单 "
                };
                for (int j = 0; j < 5; j++) {
                    MenuModel child = new MenuModel {
                        Name = "二级菜单 "
                    };
                    parent.Children.Add(child);
                }
                Menus2.Add(parent);
            }
            this._Menu2.ItemsSource = Menus2;
        }
    }
}